#include "mylayout.h"
#include <QPushButton>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QGridLayout>
#include <QDebug>
//教程如下，更多功能在练习中增加。
//https://blog.csdn.net/qq_37997682/article/details/119591036
Mylayout::Mylayout(QWidget *parent) : QWidget(parent)
{
    //这里不要设置this，不然他就在this中layout()了，与下面Vlayout->addLayout(Hlayout);冲突报错
    QHBoxLayout* Hlayout = new QHBoxLayout();

    //不能用 QPushButton btn1("H1", this); 这样出构造函数就被释放了！不显示按钮
    QPushButton *btn1 = new QPushButton("H1", this);
    QPushButton *btn2 = new QPushButton("H2", this);
    QPushButton *btn3 = new QPushButton("H3", this);

//设置大小，忽略
//    btn1.setMaximumSize(600,360);
//    btn1.setMinimumSize(100,60);

    //设置水平布局
    Hlayout->addWidget(btn1);
    Hlayout->addWidget(btn2);
    Hlayout->addWidget(btn3);
    //设置各个控件的间距
    Hlayout->setSpacing(30);

    QPushButton *btn4 = new QPushButton("H4", this);
    QPushButton *btn5 = new QPushButton("H5", this);
    QPushButton *btn6 = new QPushButton("H6", this);
    QPushButton *btn7 = new QPushButton("H7", this);

    //设置垂直布局
    QVBoxLayout* Vlayout = new QVBoxLayout();
    Vlayout->addLayout(Hlayout);
    Vlayout->addWidget(btn4);
    Vlayout->addWidget(btn5);
    Vlayout->addWidget(btn6);
    //加弹簧
    Vlayout->addStretch(1);
    Vlayout->addWidget(btn7);


// 如果报早已setlayout的错误，去掉最后一句，加入这个
//    QWidget* centralWidget = new QWidget(this);
//    centralWidget->setLayout(Hlayout);

    this->setLayout(Vlayout);

}
